<template>
  <div class="p20 bg-white console">
    <el-form :model="form" ref="form" class="mt20 overflow pl15 pr15" label-position="right">
      <el-row>
        <el-col :span="9" class="mb15 form-inp">
          <el-form-item label="公告类型：" prop="announcement" :label-width="labelWidth">
            <span class="ml20">{{form.announcement}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" justify="space-around">
        <el-col :span="24" class="mb15">
          <el-form-item label="公告标题：" prop="title" :label-width="labelWidth">
            <span class="ml20">
              <i v-if="form.istop" class="theme">[置顶]</i>
              {{form.title}}
            </span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" justify="space-around">
        <el-col :span="24" class="mb15 form-inp">
          <el-form-item label="公告内容：" prop="content" :label-width="labelWidth">
            <span v-html="form.content"></span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" justify="space-around">
        <el-col :span="24" class="mb15">
          <el-form-item label="状态：" prop="status" :label-width="labelWidth">
            <span class="ml20">{{form.status}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" justify="space-around">
        <el-col :span="12" class="mb15">
          <el-form-item>
            <GoBack />
            <el-button style="width: 120px;" class="theme-btn" @click="handleEdit">编辑</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <PhotoDialog @showPic="handleShowPic" :showPic="showPic" :isShowPic="isShowPic"></PhotoDialog>
  </div>
</template>

<script>
import GoBack from "@/components/go_back";
import { getNotice } from "@/apis/information";
import PhotoDialog from "@/components/photo_dialog";

export default {
  name: "Detail_notice",
  data() {
    return {
      form: {
        name: "",
        istop: "",
        level: "",
        status: "",
        residentTime: ""
      },
      showPic: "",
      isShowPic: false,
      labelWidth: "110px"
    };
  },
  created() {
    this.getDetailNotice();
  },
  computed: {
    detailNoticeId() {
      return this.$route.query.id;
    }
  },
  methods: {
    handleShowPic(data) {
      this.showPic = data;
      this.isShowPic = !this.isShowPic;
    },
    async getDetailNotice() {
      const { object } = await getNotice({
        communityAnnouncementId: this.detailNoticeId
      });

      object.status = object.status ? "发布中" : "撤回";
      this.form = object;
      this.form.istop = object.top === 2 ? true : false;
    },
    handleEdit() {
      this.$router.push({
        name: "editNotice",
        query: {
          id: this.detailNoticeId
        }
      });
    }
  },
  components: {
    GoBack,
    PhotoDialog
  }
};
</script>

<style scoped lang="less">
</style>
